package com.wuad.platformwuad.module.study.stringMethods;

import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;

/**
 * 字符串拼接
 */
public class StringJoinerDemo {

    public static void main(String[] args) {

        // 分隔符
        CharSequence delimiter;
        // 前缀
        CharSequence prefix;
        // 后缀
        CharSequence suffix;

        StringJoiner sj = new StringJoiner(",","{","}");

        sj.add("11").add("22").add("33");

        System.out.println("输出：" + sj);


        /**
         * 不使用StringJoiner完成字符串拼接
         */
        List<String> list = new ArrayList();
        list.add("11");
        list.add("22");
        list.add("33");
    String [] str = new String[]{"11","22","33"};

        StringBuilder stringBuilder = new StringBuilder();
        for (String ss: str) {
            stringBuilder.append(ss);
            stringBuilder.append(",");
        }
        // 处理最后一个分隔符
        // 方式一：截取
        System.out.println("截取：" + stringBuilder.substring(0, stringBuilder.length()-1));
        // 方式二：替换？？？方式二方式三不能同时用
        System.out.println("替换：" + stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), ""));
        // 方式三：删除
        System.out.println("删除" + stringBuilder.deleteCharAt(stringBuilder.length()-1));
        System.out.println("不使用工具类完成字符串拼接：" + stringBuilder);


    }



}
